﻿using Architecture.API.Application.TraceabilityCommand.BreedCommand;
using MediatR;
using Traceability.Domain.BreedDomain;
using Traceability.Domain.Service.BreedService;

namespace Architecture.API.Application.TraceabilityCommandHandler.BreedCommandHandler
{
    /// <summary>
    /// 
    /// </summary>
    public class UpdateBreedCommandHandler : IRequestHandler<UpdateBreedCommand, int>
    {
        /// <summary>
        /// 养殖服务
        /// </summary>
        protected readonly IBreedService breedService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="breedService">养殖服务</param>
        public UpdateBreedCommandHandler(IBreedService breedService)
        {
            this.breedService = breedService;
        }

        /// <summary>
        /// 修改养殖信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<int> Handle(UpdateBreedCommand request, CancellationToken cancellationToken)
        {
            return await breedService.UpdateBreed(new Breed() { BreedId=request.BreedId,Quality=request.Quality,Source=request.Source,FeedingDays=request.FeedingDays,FeedBrand=request.FeedBrand,BreedingManager=request.BreedingManager,DateOfSlaughter=request.DateOfSlaughter,ProductionBatch=request.ProductionBatch,ShoppingId=request.ShoppingId, UpdatedBy=request.UpdatedBy,UpdatedDate=DateTime.Now });
        }
    }
}
